package dao

import (
	"hong/uniapp_server/domain/diary"
	"time"
)

type DiaryDao struct {
	diaryFields string
}

func NewDiaryDao() *DiaryDao {
	return &DiaryDao{
		diaryFields: generateSqlFields(diary.DiaryEntity{}),
	}
}

func (t *DiaryDao) InsertDiary(diary *diary.DiaryEntity) (int64, error) {
	sql := "INSERT INTO diary (user_id, day, weather, mood, content, created_at) VALUES (?, ?, ?, ?, ?, ?)"

	r, err := db.Exec(sql, diary.UserID, diary.Day, diary.Weather, diary.Mood, diary.Content, time.Now())
	if err != nil {
		return 0, err
	}
	return r.LastInsertId()
}
